﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Alice.Problems.PalindromeNumber
{
    // 给定一个数字，判定该数组是否是回文数字
    public class PalindromeNumberJudger
    {
        /// <summary>
        /// 判定给定num是否是回文数字
        /// </summary>
        /// <param name="num">待判断数字</param>
        /// <param name="digistsNums">num位数</param>
        /// <returns></returns>
        public static bool Judge(int num, int digistsNums)
        {
            // 递归结束条件
            if (digistsNums <= 1)
                return true;
            else
            {
                // 否则开始判断，分离首位和末尾
                int last = num % 10;
                int first = num / (int)Math.Pow(10, (digistsNums - 1));
                int newNum = (num - last - first * ((int)Math.Pow(10, (digistsNums - 1)))) / 10;
                // 如果首位和末尾的值不相等的话 ，返回false
                if (last != first)
                    return false;
                else
                    // 否则开始递归
                    return Judge(newNum, digistsNums - 2);
            }
            
        }
    }
}
